package  
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.Point;
	import ex.Circle;
	/**
	 * ...
	 * @author ...
	 */
	public class Follower extends MovingCircle
	{
		public var _target:Player;
		private var v:Point;
		private var v1:Point;
		private var v2:Point;
		private var v3:Point;
				
		public function Follower(stage: Stage, t: Player, s:Number) 
		{
			
			super(12, s); //r=12 speed=s
			//brainDead = true;
			hitpoints = 100;
			v = new Point(0, 0);
			v1 = new Point(0, 0);
			v2 = new Point(0, 0);
			_target = t;
			Draw();
			//stage.addEventListener(Event.ENTER_FRAME, movePlayer);
		}
		public function Dot(a:Point, b:Point):Number
		{
			return a.x * b.x + a.y * b.y;
		}
		
		
		override public function movePlayer(event:Event):void
		{
			if (brainDead) return;
			//graphics.
			if (!IsAlive())
			{
				dx = 0; dy = 0;
				return;
			}
//			trace(_target);
//			trace("E");
			if (_target == null) return;
			v.x = _target.x - x;
			v.y = _target.y - y;
			v1 = Point.polar(1, (rotation + 5)/180 * Math.PI);
			v2 = Point.polar(1, (rotation - 5)/180 * Math.PI);
			v3 = Point.polar(1, (rotation) / 180 * Math.PI);
			
			if (Dot(v,v2)>Dot(v,v1) && Dot(v,v2)>Dot(v,v3))
				rotation -= 5;
			else
				if (Dot(v,v1)>Dot(v,v3))
					rotation += 5;
			moveForward();
		}
		override public function destroy():void
		{
			//removeEventListener(Event.ENTER_FRAME, movePlayer);
		}
	}

}